<?php
class openapi_ctl_admin_log_response extends desktop_controller{
    var $name = "响应日志";
    var $workground = "setting_tools";

    public function index(){
        $actions[] = array(
                    'label'=>'订单接口核查',
                    'target'=>"dialog::{width:500,height:200,title:'订单接口核查'}",
                    'href'=>'index.php?app=openapi&ctl=admin_log_response&act=ordercheckshow',
                );
        $this->finder('openapi_mdl_response_log',array(
            'title'=>'响应日志',
            'use_buildin_new_dialog' => false,
            'use_buildin_set_tag'=>false,
            'use_buildin_recycle'=>true,
            'use_buildin_export'=>false,
            'use_buildin_import'=>false,
            'use_buildin_filter'=>true,
            'actions'=>$actions,
	    ));
    }
    /**
     * undocumented function
     *
     * @param  
     *
     * @return void
     * 
     * @author 张学会 <phlv@163.com>
     **/
    public function ordercheckshow()
    {
        $this->display('admin/log/response/ordercheck.html');
    }

    /**
     * undocumented function
     *
     * @param  
     *
     * @return void
     * 
     * @author 张学会 <phlv@163.com>
     **/
    public function checkresshow()
    {
        $datef = $this->getTime($_POST,true);
        $createtime = $datef['createtime'];
        $responseLogObj = app::get('openapi')->model('response_log');
        $ordersObj      = app::get('oms')->model('orders');
        $baseSuccFilter = array('api_name'=>$_POST['api_name'],'createtime|than'=>$createtime,'status'=>'succ');
        $loglist    = $responseLogObj->getList('*',$baseSuccFilter);
        $repetOrder = array();
        foreach ($loglist as $row) {
            $param = unserialize($row['appParams']);
            if (!isset($param['content']['order_bn'])) {
                continue;
            }
            $order_bn = $param['content']['order_bn'];
            if (isset($orderbns[$order_bn]) ) {
                $i = isset($repetOrder[$order_bn])?1:2;
                $repetOrder[$order_bn] = $repetOrder[$order_bn] + $i;
            }else{
                $orderbns[$order_bn] = $order_bn;
            }
        }
        $orderList = $ordersObj->getList('order_bn',array('order_bn|in'=>$orderbns));
        foreach ($orderList as $orderone) {
            $ordersTable[$orderone['order_bn']] = $orderone['order_bn'];
        }
        $diffOrder = array_diff($ordersTable,$orderbns);
        $this->pagedata['diffOrder']   = $diffOrder;
        $this->pagedata['ordersTable'] = $ordersTable;
        $this->pagedata['repetOrder']  = $repetOrder;
        $this->pagedata['orderbns']    = $orderbns;
        $this->display('admin/log/response/ordercheckres.html');





    }
    /**
     * undocumented function
     *
     * @param  
     *
     * @return void
     * 
     * @author 张学会 <phlv@163.com>
     **/
    public function getTime($post,$istotime=false)
    {
        if (!is_array($post['_DTYPE_TIME'])) {
            return array();
        }
        $res = array();
        foreach ($post['_DTYPE_TIME'] as $colum) {
            if (isset($post[$colum])) {
                $YMD = $post[$colum];
                $H   = isset($post['_DTIME_']['H'][$colum])?$post['_DTIME_']['H'][$colum]:'00';
                $M   = isset($post['_DTIME_']['M'][$colum])?$post['_DTIME_']['M'][$colum]:'00';
                $D   = isset($post['_DTIME_']['D'][$colum])?$post['_DTIME_']['D'][$colum]:'00';
                $datestr = $YMD.' '.$H.':'.$M.':'.$D;
                if ($istotime) {
                    $datestr = strtotime($datestr);
                }
                $res[$colum] = $datestr;
            }
        }
        return $res;
    }



}
?>
